home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / as5.zip / PSEUDO.C < prev    next >
C/C++ Source or Header  |  1987-12-09  |  7KB  |  171 lines

  1. /*
  2.  *      pseudo --- pseudo op processing
  3.  */
  4.  
  5. #define RMB     0       /* Reserve Memory Bytes         */
  6. #define FCB     1       /* Form Constant Bytes          */
  7. #define FDB     2       /* Form Double Bytes (words)    */
  8. #define FCC     3       /* Form Constant Characters     */
  9. #define ORG     4       /* Origin                       */
  10. #define EQU     5       /* Equate                       */
  11. #define ZMB     6       /* Zero memory bytes            */
  12. #define FILL    7       /* block fill constant bytes    */
  13. #define OPT     8       /* assembler option             */
  14. #define NULL_OP 9       /* null pseudo op               */
  15. #define PAGE    10      /* new page                     */
  16.  
  17. struct oper pseudo[] = {
  18. "bsz",  PSEUDO, ZMB,    0,
  19. "end",  PSEUDO, NULL_OP,0,
  20. "equ",  PSEUDO, EQU,    0,
  21. "fcb",  PSEUDO, FCB,    0,
  22. "fcc",  PSEUDO, FCC,    0,
  23. "fdb",  PSEUDO, FDB,    0,
  24. "fill", PSEUDO, FILL,   0,
  25. "nam",  PSEUDO, NULL_OP,0,
  26. "name", PSEUDO, NULL_OP,0,
  27. "opt",  PSEUDO, OPT,    0,
  28. "org",  PSEUDO, ORG,    0,
  29. "pag",  PSEUDO, PAGE,   0,
  30. "page", PSEUDO, PAGE,   0,
  31. "rmb",  PSEUDO, RMB,    0,
  32. "spc",  PSEUDO, NULL_OP,0,
  33. "ttl",  PSEUDO, NULL_OP,0,
  34. "zmb",  PSEUDO, ZMB,    0
  35. };
  36.  
  37. /*
  38.  *      do_pseudo --- do pseudo op processing
  39.  */
  40. do_pseudo(op)
  41. int op; /* which op */
  42. {
  43.         char    fccdelim;
  44.         int     j;
  45.         int     fill;
  46.         char    *skip_white();
  47.  
  48.         if( op != EQU && *Label )
  49.                 install(Label,Pc);
  50.  
  51.         P_force++;
  52.         switch(op){
  53.                 case RMB:                       /* reserve memory bytes */
  54.                         if( eval() ){
  55.                                 Pc +=  Result;
  56.                                 f_record();     /* flush out bytes */
  57.                                 }
  58.                         else
  59.                                 error("Undefined Operand during Pass One");
  60.                         break;
  61.                 case ZMB:                       /* zero memory bytes */
  62.                         if( eval() )
  63.                                 while( Result-- )
  64.                                         emit(0);
  65.                         else
  66.                                 error("Undefined Operand during Pass One");
  67.                         break;
  68.                 case FILL:                      /* fill memory with constant */
  69.                         eval();
  70.                         fill = Result;
  71.                         if( *Optr++ != ',' )
  72.                                 error("Bad fill");
  73.                         else{
  74.                                 Optr = skip_white(Optr);
  75.                                 eval();
  76.                                 while( Result-- )
  77.                                         emit(fill);
  78.                                 }
  79.                         break;
  80.                 case FCB:                       /* form constant byte(s) */
  81.                         do{
  82.                                 Optr = skip_white(Optr);
  83.                                 eval();
  84.                                 if( Result > 0xFF ){
  85.                                         if(!Force_byte)
  86.                                                 warn("Value truncated");
  87.                                         Result = lobyte(Result);
  88.                                         }
  89.                                 emit(Result);
  90.                         }while( *Optr++ == ',' );
  91.                         break;
  92.                 case FDB:                       /* form double byte(s) */
  93.                         do{
  94.                                 Optr = skip_white(Optr);
  95.                                 eval();
  96.                                 eword(Result);
  97.                         }while( *Optr++ == ',' );
  98.                         break;
  99.                 case FCC:                       /* form constant characters */
  100.                         if(*Operand==EOS)
  101.                                 break;
  102.                         fccdelim = *Optr++;
  103.                         while( *Optr != EOS && *Optr != fccdelim)
  104.                                 emit(*Optr++);
  105.                         if(*Optr == fccdelim)
  106.                                 Optr++;
  107.                         else
  108.                                 error("Missing Delimiter");
  109.                         break;
  110.                 case ORG:                       /* origin */
  111.                         if( eval() ){
  112.                                 Old_pc = Pc = Result;
  113.                                 f_record();     /* flush out any bytes */
  114.                                 }
  115.                         else
  116.                                 error("Undefined Operand during Pass One");
  117.                         break;
  118.                 case EQU:                       /* equate */
  119.                         if(*Label==EOS){
  120.                                 error("EQU requires label");
  121.                                 break;
  122.                                 }
  123.                         if( eval() ){
  124.                                 install(Label,Result);
  125.                                 Old_pc = Result;        /* override normal */
  126.                                 }
  127.                         else
  128.                                 error("Undefined Operand during Pass One");
  129.                         break;
  130.                 case OPT:                       /* assembler option */
  131.                         P_force=0;
  132.                         if( head(Operand,"l") )
  133.                                 Lflag=1;
  134.                         else if( head(Operand,"nol"))
  135.                                 Lflag=0;
  136.                         else if( head(Operand,"c")){
  137.                                 Cflag=1;
  138.                                 Ctotal=0;
  139.                                 }
  140.                         else if( head(Operand,"noc"))
  141.                                 Cflag=0;
  142.                         else if( head(Operand,"contc")){
  143.                                 Cflag=1;
  144.                                 }
  145.                         else if ( head(Operand,"s"))
  146.                                 Sflag = 1;
  147.                         else if ( head(Operand,"cre"))
  148.                                 CREflag = 1;
  149.                         else
  150.                                 error("Unrecognized OPT");
  151.                         break;
  152.                 case PAGE:                      /* go to a new page */
  153.                         P_force=0;
  154.                         N_page = 1;
  155.                         if (Pass == 2 )
  156.                          if (Lflag)  
  157.                           {
  158.                            printf ("\f");
  159.                            printf ("%-10s",Argv[Cfn]);
  160.                            printf ("                                   ");
  161.                            printf ("page %3d\n",Page_num++);
  162.                           }
  163.                         break;
  164.                 case NULL_OP:                   /* ignored psuedo ops */
  165.                         P_force=0;
  166.                         break;
  167.                 default:
  168.                         fatal("Pseudo error");
  169.                 }
  170. }
  171.